VALGRIND ?= valgrind
DOXYGEN ?= doxygen
CC = g++
EXTRA_CPPFLAGS ?= -ansi -pendantic -Wall
TEST_LDFLAGS = -lcppunit -ldl
TEST_CPPFLAGS = -DTEST
EXECUTABLE = main.app
TEST_EXEC = main.test
DOXYFILE = Doxyfile

all: clean docs $(EXECUTABLE) $(TEST_EXEC) submit

$(TEST_EXEC): main.c++
	$(CC) $(EXTRA_CFLAGS) $(TEST_LDFLAGS) $(TEST_CPPFLAGS) $< -o $@

$(EXECUTABLE): main.c++
	$(CC) $(EXTRA_CFLAGS) $< -o $@


submit: main.c++ submit.sed
	unifdef -UTEST -UMAKE_CACHE -DNDEBUG main.c++ | \
	./submit.sed > submit.c++
	

docs: $(DOXYFILE)
	doxygen Doxyfile >/dev/null 2>&1

clean:
	-rm -f $(EXECUTABLE) $(TEST_EXEC) $(CACHE_EXEC) submit.c++ html/*
	-rmdir html >/dev/null 2>&1

distclean: clean
	rm -f $(DOXYFILE)

$(DOXYFILE):
	$(DOXYGEN) -g
	sed -i 's/^EXTRACT_ALL\([ \t]*=[ \t]*\).*/EXTRACT_ALL\1YES/g' $@
	sed -i 's/^EXTRACT_PRIVATE\([ \t]*=[ \t]*\).*/EXTRACT_PRIVATE\1YES/g' $@
	sed -i 's/^EXTRACT_STATIC\([ \t]*=[ \t]*\).*/EXTRACT_STATIC\1YES/g' $@
	sed -i 's/^GENERATE_LATEX\([ \t]*=[ \t]*\).*/GENERATE_LATEX\1NO/g' $@
